package Gather.ImmutableGather;

import java.util.Iterator;
import java.util.Set;
import java.util.function.Consumer;

/**
 * ClassName:Gather003
 * Package:Gather.ImmutableGather
 * Description:
 *
 * @Author:ZhangXin
 * @Create2023/2/23-20:35
 * @Version:v1.0
 */
public class Gather003 {
    public static void main(String[] args) {
        /*创建不可变的Set集合
        * "张三","李四","王五","赵六"
        *
        *
        * 细节
        * 当我们要获取一个不可变的Set集合时里面的参数一定要保证唯一性*/
        Set<String> set = Set.of("张三", "李四", "王五", "赵六");

        System.out.println("Lambda表达式遍历");
        set.forEach(new Consumer<String>() {
            @Override
            public void accept(String s) {
                System.out.println(s);
            }
        });
        System.out.println("迭代器遍历");
        Iterator<String> iterator = set.iterator();
        while (iterator.hasNext()){
            String s = iterator.next();
            System.out.println(s);
        }
        System.out.println("增强for遍历");
        for (String s : set) {
            System.out.println(s);
        }
    }
}
